package com.lancoo.znbkxx.teacher.adapter

import android.os.Handler
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.model.data.BaseInfo
import kotlinx.android.synthetic.main.item_spinner.view.*

/**
 * @author : Admin
 * @date   : 2019/10/23 15:04
 * @desc   :
 */
class ClassListAdapter(layoutResId: Int, data: MutableList<String>?) :
        BaseQuickAdapter<String, BaseViewHolder>(layoutResId, data) {
    val posList = hashMapOf<Int, Boolean>().apply {
        for (i in 0..data!!.size) {
            if (i == 0) put(i, true) else
                put(i, false)
        }
    }

    override fun convert(helper: BaseViewHolder, item: String?) {
        helper.itemView.tv.text = item
        helper.itemView.tv.isChecked = posList[helper.layoutPosition]!!
        helper.itemView.tv.setOnCheckedChangeListener { buttonView, isChecked ->
            posList.forEach {
                posList[it.key] = false
            }
            posList[helper.layoutPosition] = true
            Handler().postDelayed({ notifyDataSetChanged() }, 50)
        }
    }
}